//消失的数字
//数组nums包含从0到n的所有整数，但其中缺了一个。请编写代码找出那个缺失的整数。

public class Test {

    //法1
    public static int missingNumber(int[] nums, int[] arr) {

        int sum1 = 0;
        int sum2 = 0;
        int ret = 0;
        for (int i = 0; i < nums.length; i++) {
           sum1 += nums[i];
        }
        for (int i = 0; i < arr.length ; i++) {
            sum2 += arr[i];
        }
        ret = sum1 - sum2;
        return ret;
    }
    //法2
    public static int missingNumber1(int[] nums, int[] arr) {
        int sum1 = 0;
        int sum2 = (1 + arr.length) * nums.length / 2;

        for (int i = 0; i < nums.length; i++) {
            sum1 += nums[i];
        }

        return sum2 - sum1;
    }


    public static void main(String[] args) {
         int[] nums = {0,1,2,3,4};
        int[] arr = {0,1,3,4};
       // System.out.println(missingNumber(nums,arr));
        System.out.println(missingNumber1(nums,arr));
    }
}
